﻿@{
    ViewBag.Title = "LossReportingManagement";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>报损管理</title>
    <script src="~/libs/jquery/jquery.js"></script>
    <link href="//unpkg.com/layui@2.9.16/dist/css/layui.css" rel="stylesheet">
    <script src="//unpkg.com/layui@2.9.16/dist/layui.js"></script>

    @* <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet"> *@
</head>
<body>
    <form class="layui-form layui-row">
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">报损单号：</label>
                <input type="text" style="width:170px" id="ReportNumber" value="" placeholder="请输入单号" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">条码类型： </label>
                <div class="layui-input-block" style="width:180px">
                    <select id="DamageType" lay-filter="aihao" placeholder="请选择">
                        <option value="" selected></option>
                        <option value="损坏报损">损坏报损</option>
                        <option value="丢失报损">丢失报损</option>
                        <option value="其他报损">其他报损</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">单据状态： </label>
                <div class="layui-input-block" style="width:180px">
                    <select id="Status" lay-filter="aihao" placeholder="请选择">
                        <option value="0" selected></option>
                        <option value="0">全部</option>
                        <option value="1">待审核</option>
                        <option value="2">审核成功</option>
                        <option value="3">审核失败</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-btn-container ">
            <button class="layui-btn" lay-submit lay-filter="demo-table-search">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">清空</button>
            <button type="button" class="layui-btn layui-btn-primary layui-bg-blue" id="addData"> 添加</button>
        </div>
    </form>
    <table class="layui-hide" id="test"></table>
 @*    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script> *@
    <script>
        layui.use(function () {
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var laydate = layui.laydate;
            //显示
            function show() {
                table.render({
                    elem: '#test',
                    url: '/QiData/GetLossReportingData',
                    //maxHeight: '530px',
                    //toolbar: '#TPL-treeTable-demo',
                    page: true, //开启分页
                    limit: 10,
                    limits: [10, 20, 50, 100],
                    cols: [[
                        { field: 'reportNumber', title: '报损编号', width: 150, fixed: 'left' },
                        { field: 'productName', title: '产品名称', width: 120 },
                        { field: 'productNumber', title: '产品编号', width: 150 },
                        { field: 'batchNumber', title: '批次', width: 120 },
                        { field: 'unit', title: '单位', width: 100 },
                        { field: 'quantity', title: '数量', width: 100 },
                        {
                            field: 'createDate', title: '创建日期', width: 120, templet: function (row) {
                                if (row.createDate == null) {
                                    return "";
                                }
                                else {
                                    var tmp = row.createDate.split("T")[0];
                                    return tmp;
                                }
                            }
                        },
                        { field: 'damageType', title: '报损类型', width: 100 },
                        {
                            field: 'status', title: '状态', width: 100, templet: function (row) {
                                if (row.status == '1') {
                                    return "待审核";
                                } else if (row.status == '2') {
                                    return "审核成功";
                                } else if (row.status == '3') {
                                    return "审核失败";
                                } else {
                                    return "审核中";
                                }
                            }
                        },
                        {
                            fixed: "right", title: "操作", width: 350, align: "center", templet: function (row) {
                                var tmp = '<a class="layui-btn layui-btn-xs layui-bg-blue" lay-event="detail">编辑</a>';
                                tmp += '<a class="layui-btn layui-btn-xs layui-bg-red" lay-event="delChild">删除</a>';
                                tmp += '<a class="layui-btn layui-btn-xs layui-bg-blue" lay-event="updStauts">审核</a>';
                                return tmp;
                            }
                        }
                    ]],
                });
            }
            show();//初始化显示
            // 搜索提交
            form.on('submit(demo-table-search)', function (data) {
                var recptname = $("#Status").val();    //分类名称
                var vendorname = $("#DamageType").val();    //是否启用
                var recptcode = $("#ReportNumber").val();
                // 执行搜索重载
                table.reload('test', {
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    },
                    where: {
                        Status: recptname,
                        DamageType: vendorname,
                        ReportNumber: recptcode,
                    }// 搜索的字段
                });
                return false; // 阻止默认 form 跳转
            });

            // 添加分类
            $("#addData").click(function () {
                layer.open({
                    type: 2,
                    title: '新增报损',
                    shadeClose: true, // 点击遮罩区域，关闭弹层
                    scrollbar: false, // 暂时屏蔽浏览器滚动条
                    skin: 'layui-layer-rim', //加上边框
                    area: ['90%', '90%'], //宽高
                    content: '/QiData/AddLossReportingManagement',
                    end: function () {
                        show();//刷新父级页面列表方法，类似于回调函数
                    }
                });
            });

            // 单元格工具事件
            table.on('tool(test)', function (obj) {
                var layEvent = obj.event; // 获得 lay-event 对应的值
                var trData = obj.data;
                if (layEvent === "detail") {
                    var data = obj.data;//获取表单中的点击按钮的那一行数据

                    layer.open({
                        title: '编辑报损单',
                        skin: 'layui-layer-rim', //加上边框
                        type: 2,
                        shadeClose: true, // 点击遮罩区域，关闭弹层
                        scrollbar: false, // 暂时屏蔽浏览器滚动条
                        area: ['80%', '80%'],
                        content: '/QiData/UpdLossReportingManagement',
                        end: function () {
                            show();
                        }
                    });
                } else if (layEvent === "delChild") {
                    layer.confirm("确定要删除吗？", function (data) {
                        var id = { id: trData.id };
                        // 此处可执行 Ajax 等操作
                        $.get('/QiData/DeleteLossReporting', id, function (res) {
                            if (res) {
                                layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
                                    obj.del();
                                    // 刷新表格
                                    table.reload('test');
                                });
                            } else {
                                layer.msg("删除失败", { icon: 2, time: 1000 });
                            }
                        });
                    });
                } else if (layEvent === "updStauts") {
                    layer.confirm("确定要修改状态吗？", function (data) {
                        var id = { id: trData.id };
                        // 此处可执行 Ajax 等操作
                        $.get('/QiData/UpdateStutes', id, function (res) {
                            if (res) {
                                layer.msg("状态修改成功", { icon: 1, time: 1000 }, function () {
                                    // 刷新表格
                                    table.reload('test');
                                });
                            } else {
                                layer.msg("状态修改失败", { icon: 2, time: 1000 });
                            }
                        });
                    });
                }
            });
        });
    </script>
</body>
</html>